<?php
include("../../config.php");
include(FILE_ROOT."/common/db.php");
include(FILE_ROOT."/common/WorkOrder.php");
include(FILE_ROOT."/common/user_client.php");
include(FILE_ROOT."/common/common_function.php");	
/*if(!checkIsLogin()){
    echo '{"status":-2,"message":"没有权限！","data":""}';
    return;
}*/

$workorder=new WorkOrder();
$op = empty($_POST["action"])?$_GET["action"]:$_POST["action"];
$db=new DB();
switch($op){ 
	case 'create':
		$arr=array();
		//获取创建者的Id
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$uid1=$db->getOne("SELECT uid from chu_user where token='".$token."'");
		$arr['CreatePersonId']=$uid1['uid'];
		//获取客户的id
		$cname=empty($_POST['cname'])?$_GET["cname"]:$_POST["cname"];
		$uid2=$db->getOne("SELECT uid from chu_user where uname='".$cname."'");

		$arr['ClientId']=$uid2['uid'];
		$arr['Type']=empty($_POST['Type'])?$_GET["Type"]:$_POST["Type"];
		$arr['OutletId']=empty($_POST['OutletId'])?$_GET["OutletId"]:$_POST["OutletId"];
		$arr['Context']=empty($_POST['Context'])?$_GET["Context"]:$_POST["Context"];
		$arr['Status']="未处理";
		$arr['CreateTime']=Time();
		$arr['DateTime']=empty($_POST['Context'])?strtotime($_GET['DateTime']):strtotime($_POST['DateTime']);//时间转换时间戳
		$workorder->create($arr)->end();
		//还需要做推送
		break;
	case 'update':
		$arr=array();
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$uid=$db->getOne("SELECT uid from chu_user where token='".$token."'");
		$arr['HandlerId']=$uid['uid'];
		$arr['Id']=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$arr['Status']=empty($_POST['Status'])?$_GET["Status"]:$_POST["Status"];
		$arr['Handle']=empty($_POST['Handle'])?$_GET["Handle"]:$_POST["Handle"];
		$workorder->update($arr)->end();
		//还需要做推送
		break;
	case 'orderList1':
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$uid=$db->getOne("SELECT uid from chu_user where token='".$token."'");
		$uid=$uid['uid'];
		$data=$workorder->workOrderListByClient($uid);
		//p($data);die;
		$workorder->data($data)->end();
		break;
	case 'orderList2':
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$uid=$db->getOne("SELECT uid from chu_user where token='".$token."'");
		$uid=$uid['uid'];
		$data=$workorder->workOrderListByStaff($uid);
		$workorder->data($data)->end();
		break;
	case 'orderListByClient':
		$token=empty($_POST['token'])?$_GET["token"]:$_POST["token"];
		$uid=$db->getOne("SELECT uid from chu_user where token='".$token."'");
		$uid=$uid['uid'];
		$data=$workorder->workOrderListByClient2($uid);
		//p($data);die;
		$workorder->data($data)->end();
		break;	
	case 'Detail':
		$wid=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->workOrderDetailById($wid);
		//p($data);die;
		$workorder->data($data)->end();
		break;
	case 'routeList':
		$wid=empty($_POST['Id'])?$_GET["Id"]:$_POST["Id"];
		$data=$workorder->routeLogById($wid);
		//p($data);die;
		$workorder->data($data)->end();
		break;
}

?>